package com.ldr.custom.spring.v3.aop.intercept;

import com.ldr.custom.spring.v3.aop.GPJoinPoint;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 前置拦截器
 */
public class GPMethodBeforeAdviceInterceptor extends GPAbstractAspectAdvice implements GPMethodInterceptor {


    private GPJoinPoint joinPoint;

    public GPMethodBeforeAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private void before(Method method, Object[] args, Object target) throws InvocationTargetException, IllegalAccessException {
        super.invokeAdviceMethod(this.joinPoint,null,null);
    }

    @Override
    public Object invoke(GPReflectiveMethodInvocation mi) throws Throwable {
        this.joinPoint=mi;
        before(mi.getMethod(), mi.getArguments(), mi.getTarget());

        return mi.proceed();
    }
}
